package com.example.demotest.config;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ModelMapperConfig {

    @Bean
    public ModelMapper modelMapper() {
        ModelMapper modelMapper = new ModelMapper();
        
        // 配置ModelMapper
        modelMapper.getConfiguration()
            .setMatchingStrategy(MatchingStrategies.STRICT) // 使用严格匹配策略
            .setSkipNullEnabled(true) // 跳过null值
            .setAmbiguityIgnored(true) // 忽略歧义
            .setFieldMatchingEnabled(true) // 启用字段匹配
            .setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE); // 允许访问私有字段
        
        return modelMapper;
    }
}